package com.yfq.springframework.core.io;

import java.net.URL;

/**
 * @author 姚凤桥
 * @date 2023/1/19 12:11
 * @description
 */
public class DefaultResourceLoader implements ResourceLoader {
    private static final String CLASSPATH = "classpath:";

    @Override
    public Resource getResource(String location) {
        if (location.startsWith(CLASSPATH)) {
            return new ClassPathResource(location.substring(CLASSPATH.length()));
        }

        try {
            URL url = new URL(location);
            return new UrlResource(url);
        } catch (Exception e) {
            return new FileSystemResource(location);
        }
    }
}
